//package com.asia5b.a5mall.order.activity
//
//import android.content.ClipData
//import android.content.ClipboardManager
//import android.content.Context
//import androidx.recyclerview.widget.LinearLayoutManager
//import android.text.TextUtils
//import com.alibaba.android.arouter.facade.annotation.Route
//import com.asia5b.a5bmall.resource.ActCons
//import com.asia5b.a5mall.middleware.base.SimpleActivity
//import com.asia5b.a5mall.middleware.config.Asia5bPayUtils
//import com.asia5b.a5mall.middleware.event.AsiaPayEvent
//import com.asia5b.a5mall.middleware.logic.contract.order.OrderDetailActivityView
//import com.asia5b.a5mall.middleware.logic.presenter.order.OrderDetailActivityPresenter
//import com.asia5b.a5mall.middleware.model.order.OrderDetailModel
//import com.asia5b.a5mall.middleware.model.order.OrderPayModel
//import com.asia5b.a5mall.middleware.model.order.TradeType
//import com.asia5b.a5mall.middleware.model.bean.MenuBean
//import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
//import com.asia5b.a5mall.middleware.mvp.BaseMvpActivity
//import com.asia5b.a5mall.middleware.mvp.WCallBack
//import com.asia5b.a5mall.middleware.utils.*
//import com.asia5b.a5mall.middleware.widget.CancelSureDialog
//import com.asia5b.a5mall.order.R
//import com.asia5b.a5mall.order.adapter.OrderDetailmAdapter
//import com.asia5b.a5mall.order.adapter.OrderDetailGoodsAdapter
//import com.asia5b.a5mall.order.databinding.ActivityOrderdetailBinding
//import com.asia5b.a5mall.order.di.OrderLaunch
//import com.asia5b.a5mall.order.fragment.LogisDF
//import com.asia5b.a5mall.order.widget.OrderCancelDF
//import com.chad.library.adapter.base.BaseQuickAdapter
//import kotlinx.android.synthetic.main.activity_orderdetail.*
//import org.greenrobot.eventbus.EventBus
//import org.greenrobot.eventbus.Subscribe
//import org.greenrobot.eventbus.ThreadMode
//
///**
// * Created by zhangyuncai on 2020/1/13.
// * @Note   订单详细
// */
//@Route(path = ActCons.OrderDetailActivity)
//class OrderDetailActivity : BaseMvpActivity<OrderDetailActivityView, OrderDetailActivityPresenter, ActivityOrderdetailBinding>(), OrderDetailActivityView {
//    override var sIsDark = true
//
//    //订单号
//    var orderSn: String = ""
//    var orderDetailModel = OrderDetailModel()
//
//    val actionDatas = arrayListOf<MenuBean>()
//    val mAdapter = OrderDetailmAdapter(actionDatas)
//    val actionRecyclerView by lazy { rv_orderdetail_action }
//
//    override fun getLayoutId(): Int {
//        EventBus.getDefault().register(this)
//        orderSn = intent.getStringExtra("orderSn") ?: ""
//        return R.layout.activity_orderdetail
//    }
//
//    override fun bindDagger() {
//        OrderLaunch.component.inject(this)
//    }
//
//    override fun initView() {
//        getOrderDetail()
//
//        actionRecyclerView.run {
//            layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.HORIZONTAL, false)!!
//            adapter = mAdapter
//        }
//    }
//
//    fun setView() {
//        //tv_orderdetail_expressname 快递名称
//        tv_orderdetail_expressname.text = orderDetailModel.logi_name
//
//        //ll_orderdetail_expressstate 物流状态
//        //iv_orderdetail_expressstate 物流状态
//        //tv_orderdetail_expressstate 物流状态
//        tv_orderdetail_expressstate.text = orderDetailModel.order_status_text_text
//
//        //收货人姓名 tv_orderdetail_receivename
//        tv_orderdetail_receivename.text = "${orderDetailModel.ship_name} ,${orderDetailModel.ship_mobile}"
//        //收货地址 tv_orderdetail_receiveaddress
//        tv_orderdetail_receiveaddress.text = orderDetailModel.address
//
//        //订单编号 tv_orderdetail_ordernum
//        tv_orderdetail_ordernum.text = orderDetailModel.sn
//        //订单编号复制 tv_orderdetail_ordernum_copy
//        tv_orderdetail_ordernum_copy.setOnClickListener {
//            val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
//            val clip = ClipData.newPlainText("Asia5B", orderDetailModel.sn)
//            cm.primaryClip = clip
//            showMessage(getString(R.string.success))
//        }
//        //下单时间 tv_orderdetail_ordertime
//        var create_time = WTimeUtils.format("${orderDetailModel.create_time * 1000}", WTimeUtils.text_yyyy_MM_dd)
//        tv_orderdetail_ordertime.text = create_time
//        //支付方式 tv_orderdetail_paytype
//        tv_orderdetail_paytype.text = orderDetailModel.payment_type
//        //支付时间 tv_orderdetail_paytime
//        var payment_time = WTimeUtils.format("${orderDetailModel.payment_time * 1000}", WTimeUtils.text_yyyy_MM_dd)
//        tv_orderdetail_paytime.text = payment_time
//        //送货时间 tv_orderdetail_sendtime
//        tv_orderdetail_sendtime.text = orderDetailModel.receive_time
//        //发票类型
//        //商品总价 tv_orderdetail_goodsprice
//        CurrencyPriceBuilder3().run {
//            textView=tv_orderdetail_goodsprice
//            price=orderDetailModel.goods_price
//            priceList=orderDetailModel.goods_price_list
//            build()
//        }
//        //国内运费 tv_orderdetail_localeprice
//        CurrencyPriceBuilder3().run {
//            textView=tv_orderdetail_localeprice
//            price=orderDetailModel.shipping_price
//            priceList=orderDetailModel.shipping_price_list
//            build()
//        }
//        //国际运费 tv_orderdetail_interprice
//        CurrencyPriceBuilder3().run {
//            textView=tv_orderdetail_interprice
//            price=orderDetailModel.international_price
//            priceList=orderDetailModel.international_price_list
//            build()
//        }
//        //订单总价 tv_orderdetail_orderprice
//        CurrencyPriceBuilder3().run {
//            textView=tv_orderdetail_orderprice
//            price=orderDetailModel.order_price
//            priceList=orderDetailModel.order_price_list
//            build()
//        }
//        //实付款 tv_orderdetail_price
//        CurrencyPriceBuilder3().run {
//            textView=tv_orderdetail_price
//            price=orderDetailModel.need_pay_money
//            priceList=orderDetailModel.need_pay_money_list
//            build()
//        }
//
//        //设置商品详情
//        setGoodsView()
//
//        //设置点击事件
//        actionDatas.clear()
//        actionDatas.addAll(orderDetailModel.getActionList())
//        mAdapter.notifyDataSetChanged()
//    }
//
//    /**
//     * 商品列表
//     */
//    fun setGoodsView() {
//        //rv_orderdetail_goods
//        orderDetailModel.order_sku_list?.run {
//            val goodsAdapter = OrderDetailGoodsAdapter(this)
//            val adapter = goodsAdapter
//            rv_orderdetail_goods.layoutManager = LinearLayoutManager(mActivity)
//            rv_orderdetail_goods.adapter = adapter
//            goodsAdapter.onItemChildClickListener = BaseQuickAdapter.OnItemChildClickListener { t1, view, position ->
//                val model = goodsAdapter.getItem(position) as AbsGoodsModel
//                when (view.id) {
//                    R.id.tv_orderdetail_aftersale -> {
//                        push(ActCons.OrderAfterSaleActivity, {
//                            it.withString("orderSn", orderSn)
//                            it.withInt("skuId", model.absGoodsId)
//                        })
//                    }
//                    R.id.tv_orderdetail_addcart -> {
//                        presenter.addCart(model.absGoodsId)
//                    }
//                }
//            }
//            goodsAdapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { t1, view, position ->
//                val model = goodsAdapter.getItem(position) as AbsGoodsModel
//                startGoodsDetailActivity(mActivity,model.absGoodsId)
//            }
//        }
//    }
//
//
//    override fun initEvent() {
//        mAdapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { t1, t2, position ->
//            val menuBean = mAdapter.getItem(position) as MenuBean
//            when (menuBean.name) {
//                "allow_rog" -> {//确认收货
//                    CancelSureDialog(mActivity,  R.string.orderdetail_confirmorder_sure, R.string.goods_deleterecord_cancel,R.string.orderdetail_confirmorder_content
//                            , WCallBack<Boolean> { b ->
//                        if (b) {
//                            presenter.rog(orderSn)
//                        }
//                    }).show()
//
//                }
//                "allow_pay" -> {//去付款
//                    Asia5bPayUtils.getAuthorization(mActivity as SimpleActivity, true) { isCanSkip ->
//                        if (isCanSkip) {
//                            presenter.getTradeSerialNo(orderSn)
//                        }
//                    }
//
//                }
//                "allow_comment" -> {//评价晒单
//                    push(ActCons.PostCommentActivity, {
//                        it.withSerializable("data", orderDetailModel)
//                    })
//                }
//                "check_logis" -> {//查看物流
//                    LogisDF().apply {
//                        this.orderDetailModel=orderDetailModel
//                    }.show(supportFragmentManager,"LogisDF")
//                }
//                "allow_apply_service" -> {//申请售后
//                    push(ActCons.OrderAfterSaleActivity, {
//                        it.withString("orderSn", orderSn)
//                    })
//                }
//                "cancel_order" -> {//取消订单
//                    val allowServiceCancel = orderDetailModel.order_operate_allowable_vo?.allow_service_cancel
//                            ?: false
//                    if (!allowServiceCancel) {
//                        val orderCancelDF = sNewStanceFragment(mActivity, OrderCancelDF::class.java)
//                        orderCancelDF.show(supportFragmentManager, "OrderCancelDF")
//                        orderCancelDF.setCallBack<String> { reson ->
//                            presenter.cancel(orderSn, reson)
//                        }
//                    } else {
//                        push(ActCons.OrderAfterSaleActivity, {
//                            it.withString("orderSn", orderSn)
//                        })
//                    }
//                }
//            }
//        }
//    }
//    override fun initData() {
//
//    }
//    fun getOrderDetail() {
//        presenter.getOrderDetail(orderSn)
//    }
//
//    override fun getOrderDetailResult(model: OrderDetailModel?) {
//        if (model != null) {
//            this.orderDetailModel = model!!
//            setView()
//        }
//    }
//
//    override fun cancelResult() {
//        pop()
//    }
//
//    override fun rogResult() {
//        pop()
//    }
//
//    var waitOrderPayModel: OrderPayModel? = null
//    override fun getTradeSerialNoResult(tradeSerialNo: String?) {
//        tradeSerialNo?.run {
//            waitOrderPayModel = OrderPayModel()
//            waitOrderPayModel!!.run {
//                tradeType = TradeType.Order
//                sn = tradeSerialNo
//                payPrice = orderDetailModel.need_pay_money
//                Asia5bPayUtils.skipPay(mActivity,waitOrderPayModel!!)
//            }
//
//        }
//    }
//
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    fun paySuccess(tradeSerialNo: String?) {
//        waitOrderPayModel?.let {
//            if (TextUtils.equals(it.sn, tradeSerialNo)) {
//                Asia5bPayUtils.checkOrderPayState(this, it.orderSn) {
//                    if (it) {
//                        EventBus.getDefault().post(AsiaPayEvent(orderDetailModel!!.sn))
//                        pop()
//                    }
//                }.joinManager(disposableManager)
//            }
//        }
//    }
//
//    override fun onDestroy() {
//        EventBus.getDefault().unregister(this)
//        super.onDestroy()
//    }
//}